'use strict';

const baseController =require('./baseController.js');

class loginController extends baseController {
    async index() {
        let {service, request, query} = this.ctx;

        this.ctx.body = "loginController"
    }

    async doLogin() {
        let {service, request, query} = this.ctx;
        let modalJson = request.body;
        let listResult = await service.loginService.list(modalJson);
        console.log("doLogin");
        console.log(listResult);
        if(listResult.length>0){
            // 1、保存用户信息
            this.ctx.session.userinfo=listResult[0];

            await this.success({});
        }else{
            await this.error({message:"用户名或密码错误"});
        }
    }
    async outLogin() {
        let {service, request, query} = this.ctx;
        this.ctx.session.userinfo=null;
        await this.success({message:"退出登录成功"});
    }
    //二维码
    async verify() {
        var captcha=await this.service.tools.captcha();  //服务里面的方法
        this.ctx.response.type = 'image/svg+xml';   /*指定返回的类型*/

        this.ctx.body=captcha.data;      /*给页面返回一张图片*/

    }
}

module.exports = loginController;

//router.get('/admin/loginController/index',controller.admin.loginController.index);
